package com.sjme.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sjme.domain.interview.dto.InterviewEvaluationDto;
import com.sjme.domain.interview.vo.InterviewEvaluationVo;
import com.sjme.domain.interview.ArrangeInterview;
import com.sjme.domain.interview.dto.InterviewInfoDto;
import com.sjme.domain.interview.vo.InterviewInfoVo;
import com.sjme.service.InterviewEvaluationService;
import com.sjme.service.InterviewInfoService;
import com.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.constant.ResultConstant.ERROR;

@Slf4j
@RestController
@RequestMapping("/interview")
public class InterviewController {
    @Autowired
    private InterviewInfoService interviewInfoService;
    @Autowired
    private InterviewEvaluationService interviewEvaluationService;

    @PostMapping("/arrangeInterview")
    public Result arrangeInterview(@RequestBody ArrangeInterview arrangeInterview) {
        try {
            return interviewInfoService.arrangeInterview(arrangeInterview);
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.error(ERROR, e.getMessage());
        }
    }

    @PostMapping("/getInterviewInfo")
    public Result getInterviewInfo(@RequestBody InterviewInfoDto interviewInfo) {
        try {
            IPage<InterviewInfoVo> interviewInfoRes = interviewInfoService.getInterviewInfo(interviewInfo);
            return Result.success(interviewInfoRes);
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.error(ERROR, e.getMessage());
        }
    }

    @PostMapping("/getInterviewEvaluation")
    public Result getInterviewEvaluation(@RequestBody InterviewEvaluationDto interviewEvaluation) {
        try {
            IPage<InterviewEvaluationVo> res = interviewEvaluationService.queryInterviewEvaluation(interviewEvaluation);
            return Result.success(res);
        } catch (Exception e) {
            log.error(e.getMessage());
            return Result.error(ERROR, e.getMessage());
        }
    }
}
